package com.stone.framework.basic.dict.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import com.stone.framework.basic.dict.entity.DictCategory;
import com.stone.framework.core.util.JpaSpecifications;

@Repository
public interface DictCategoryRepository
    extends JpaRepository<DictCategory, Long>, JpaSpecificationExecutor<DictCategory> {

    default Page<DictCategory> findAll(DictCategory entity, Pageable pageable) {
        return this.findAll(Specification.where(JpaSpecifications.<DictCategory>contains("code", entity.getCode()))
            .and(JpaSpecifications.contains("name", entity.getName()))
            .and(JpaSpecifications.contains("desc", entity.getDesc()))
            .and(JpaSpecifications.equals("state", entity.getState())), pageable);
    }

    List<DictCategory> findByCode(String code);

}
